home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / video / fly8111-.000 / fly8111- / fly8 / heading.c < prev    next >
C/C++ Source or Header  |  1979-12-31  |  6KB  |  271 lines

  1. /* --------------------------------- heading.c ------------------------------ */
  2.  
  3. /* This is part of the flight simulator 'fly8'.
  4.  * Author: Eyal Lebedinsky (eyal@ise.canberra.edu.au).
  5. */
  6.  
  7. /* paint the Head Up Display: heading.
  8. */
  9.  
  10. #include "plane.h"
  11.  
  12.  
  13. extern void FAR
  14. show_heading (HUD *h, VIEW *view, OBJECT *p, int sx, int sy, int maxx, int maxy,
  15.     int orgx, int orgy, int ttx, int tty, int tx, int ty, int ss,
  16.     int shifty, int VVD[2])
  17. {
  18.     int    hud, hud1, top, big, fine, xfine, fa18, f16, f15, fc, knots;
  19.     int    ether, gear, scale_ref, scale_len, x, y, base, dbase;
  20.     int    s, sl, x0, y0, dm, i, ex, ty1, ty2;
  21.     long    t;
  22.     ANGLE    a;
  23.     LVECT    *R;
  24.     OBJECT    *target;
  25.  
  26.     hud = EX->hud;
  27.     hud1 = EX->hud1;
  28.     fine = hud & HUD_FINE;
  29.     xfine = hud & HUD_XFINE;
  30.     big = hud & HUD_BIG;
  31.     top = hud1 & HUD_TOP;
  32.     knots = hud1 & HUD_KNOTS;
  33.     i = hud1 & HUD_TYPES;
  34.     fa18  = i == HUD_FA18;
  35.     f16   = i == HUD_F16;
  36.     f15   = i == HUD_F15;
  37.     fc    = i == HUD_CLASSIC;
  38.     ether = i == HUD_ETHER;
  39.     gear  = EX->equip & EQ_GEAR;
  40.  
  41.     if (sx < 100) {
  42.         if (xfine)
  43.             fine = 1;
  44.         xfine = 0;
  45.     }
  46.  
  47.     if (f15) {
  48.         top = !gear;
  49.         scale_len = top ? 20 : 16;
  50.         scale_ref = 20;
  51.         sl = fmul (sx, F15HEADS);
  52.     } else if (f16) {
  53.         scale_ref = scale_len = 12;
  54.         sl = fmul (sx, F16HEADS);
  55.         big = 1;
  56.     } else if (fa18) {
  57.         scale_ref = scale_len = 16;
  58.         sl = fmul (sx, F18HEADS);
  59.     } else if (ether) {
  60.         if (h->flags & HF_ETHERFRAME)
  61.             sl = maxx - ss;        /* use full window */
  62.         else
  63.             sl = sx - ss;        /* use full HUD */
  64.         scale_ref = scale_len = 25;
  65.     } else /* classic */ {
  66.         scale_ref = 25;
  67.         scale_len = 16;
  68.         sl = sx;
  69.     }
  70.  
  71. /* This logic will show true heading (the hud will match the scenery). The
  72.  * problem is that the hud is too narrow for comfortable reading.
  73. */
  74.     if (EX->hud3 & HUD_TRUEHEADING) {
  75.         x = muldiv (VP->maxx, sl, maxx);
  76.         a = ATAN (x, VP->z);
  77.         scale_ref = ANG2DEG (a);    /* HUD width in degrees */
  78.         if (scale_ref < 1)
  79.             scale_ref = 1;
  80.         scale_len = scale_ref;
  81.     }
  82.  
  83.     ty1 = -tty;
  84.     ty2 = 2*ty1;
  85.     if (f15) {
  86.         base = orgy - fmul (sy, top ? F15HEADH : F15HEADL);
  87.         dbase = base+ty2;
  88.     } else if (f16) {
  89.         ty1 = -ty1;
  90.         ty2 = -ty2;
  91.  
  92. /* The heading scale follows the vv. In 'gear' mode it is at the top, but not
  93.  * more than F16HEADTOP above the vv. In 'normal' mode it is low at
  94.  * F16CNTR+F16HEAD but sinks away from the vv.
  95. */
  96.         if (gear) {
  97.             base = ty*(3+4);
  98.             y = -VVD[Y] - fmul (sy, F16HEADTOP);    /* vv center */
  99.             if (base < y)
  100.                 base = y;
  101.             base += orgy;
  102.             dbase = base + ty2 + ss;
  103.         } else {
  104.             base = fmul (sy, F16CNTR+F16HEAD);
  105.             y = -VVD[Y] + fmul (sy, RVV) + ty2*2;    /* vv limit */
  106.             if (base < y)
  107.                 base = y;
  108.             dbase = base+ty2+ss;
  109.             y = sy + shifty;        /* bottom line */
  110.             if (dbase > y) {
  111.                 dbase = y;
  112.                 base = dbase - (ty2 + ss);
  113.             }
  114.             base += orgy;
  115.             dbase += orgy;
  116.         }
  117.     } else if (fa18) {
  118.         base = orgy - fmul (sy, gear ? F18HEADG : F18HEAD);
  119.         dbase = base+ty2;
  120.     } else if (top) {
  121.         base = orgy - sy + shifty;
  122.         dbase = base+ty2;
  123.         if (big)
  124.             dbase += ss;
  125.     } else {
  126.         base = orgy + sy + shifty;
  127.         ty1 = -ty1;
  128.         ty2 = -ty2;
  129.         dbase = base+ty2;
  130.         if (!big)
  131.             dbase += ss;
  132.     }
  133.  
  134.     gr_color (ST_HFG);
  135.  
  136. /* show aoa on left.
  137. */
  138.     if (fc) {
  139.         if (top)
  140.             y = base + ss;
  141.         else
  142.             y = base;
  143.  
  144.         x = orgx - sx;
  145.         stroke_char (x, y, 'A', ss, ST_HFG);
  146.         stroke_frac (x+ss, y, ANG2DEG00(EX->aoa)/10,
  147.             0, 1, ss, ST_HFG);
  148.     }
  149.  
  150.     if (!(EX->hud2 & HUD_HEADING) || (EX->hudmode & HM_DECLUTTER))
  151.         return;
  152.  
  153. /* Show heading scale.
  154. */
  155.     a = -p->a[Z];
  156.     if (a >= 0) {
  157.         y0 = (int)(a % (D90/9));
  158.         ex = 10*(int)(a / (D90/9));
  159.     } else {
  160.         a = -a;
  161.         y0 = D90/9 - (int)(a % (D90/9));
  162.         ex = -10*(int)(a / (D90/9)) - 10;
  163.     }
  164.  
  165.     dm = num_size (9L, ss);
  166.     if (hud&HUD_FULLHEADING)
  167.         dm = dm * 3 / 2;
  168.  
  169.     s = muldiv (y0, 90, D90);        /* degrees */
  170.     x0 = -y0 + muldiv (s, D90, 90);        /* fraction */
  171.     x0 = orgx + muldiv (x0, sl, D90/90*scale_ref);
  172.     if (f15 || (fa18 && top)) {
  173.         x = muldiv (scale_len, sl, scale_ref);
  174.         gr_move (orgx - x, base);
  175.         gr_draw (orgx + x, base);
  176.     }
  177.     for (i = 1-scale_len, s += i; i <= scale_len; ++i, ++s) {
  178.         x = x0 + muldiv (i, sl, scale_ref);
  179.         if (0 == s%10) {
  180.             gr_move (x, base);
  181.             gr_draw (x, base+ty2);
  182.             t = (ex + s + 360) % 360;
  183.             if (hud&HUD_FULLHEADING)
  184.                 stroke_frac (x-dm, dbase, t, 3, 0, ss, ST_HFG);
  185.             else if (!fc)
  186.                 stroke_frac (x-dm, dbase, t/10, 2, 0, ss,
  187.                     ST_HFG);
  188.             else if (xfine || (i >= -11 && i <= 11)) {
  189.                 dm = num_size (t, ss);
  190.                 stroke_num (x-dm/2, dbase, t, ss, ST_HFG);
  191.             }
  192.         } else if (fine) {
  193.             if (0 == s%2) {
  194.                 gr_move (x, base);
  195.                 gr_draw (x, base+ty1);
  196.             }
  197.         } else if (0 == s%5) {
  198.             gr_move (x, base);
  199.             gr_draw (x, base+(xfine?ty2:ty1));
  200.         } else if (xfine) {
  201.             gr_move (x, base);
  202.             gr_draw (x, base+ty1);
  203.         }
  204.     }
  205.  
  206.     if (fa18||f15) {
  207.         x = tx + tx/2;
  208.         gr_move (orgx-x, base+2*ty);    /* inverted V */
  209.         gr_draw (orgx,   base);
  210.         gr_draw (orgx+x, base+2*ty);
  211.     } else {
  212.         y = base;
  213.         if (f16) {
  214.             y0 = (ty1 = -ty1);
  215.         } else if (big) {
  216.             y += ty2;
  217.             if (top)
  218.                 y += ss;
  219.             else
  220.                 y -= ss;
  221.             y0 = ty1;
  222.         } else
  223.             y0 = -ty1;
  224.  
  225.         gr_move (orgx, y); /* reading mark */
  226.         gr_draw (orgx, y+(f16?4:3)*y0);
  227.     }
  228.  
  229. /* show ils/target heading.
  230. */
  231.     if (EX->hud2 & HUD_ILS)
  232.         R = &ils[EX->ils-1].R;
  233.     else if (T(target = EX->target) && target->id == EX->tid)
  234.         R = &target->R;
  235.     else
  236.         R = 0;
  237.  
  238.     if (R) {
  239.         long        hx, hy;
  240.         ANGLE        ref;
  241.  
  242.         hx = ((*R)[X] - p->R[X])/VONE;
  243.         hy = ((*R)[Y] - p->R[Y])/VONE;
  244.         i = ihypot2d ((int)(hx/100), (int)(hy/100));
  245.         EX->ilsRange = knots ? fmul (i, FONE/18*10) : i;
  246.  
  247.         t = labs(hx) + labs(hy);
  248.         while (t > 0x7fffL) {
  249.             hx >>= 1;
  250.             hy >>= 1;
  251.             t  >>= 1;
  252.         }
  253.         a = ATAN ((int)hx, (int)hy);
  254.         EX->ilsHeading = a;
  255.         a += p->a[Z];
  256.         ref = DEG2ANG (scale_len);
  257.         if (a > ref)
  258.             a = ref;
  259.         else if (a < -ref)
  260.             a = -ref;
  261.  
  262.         ref = DEG2ANG (scale_ref);
  263.         x = orgx + muldiv ((int)a, sl, (int)ref);
  264.         y = fa18 ? -ty2 : ty1;
  265.         gr_color (ST_HFGI);
  266.         gr_move (x-tx, base+y);
  267.         gr_draw (x,    base);
  268.         gr_draw (x+tx, base+y);
  269.     }
  270. }
  271.